#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const int N=2e5+10;
#define INF 0x3f3f3f3f;
typedef long long int ll;
#define close(); std::ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);
//----------------------------------------------------------------------------//
ll k,x;
void solve()
{
	cin>>k>>x;

	ll top=k*(k+1)/2;
	ll low=(k-1)*(k-1+1)/2;
	if(top+low<=x)
	{
		cout<<k*2-1<<'\n';
		return;
	}

	if(x<=top)
	{
		ll l=0,r=k;
		while(l<r)
		{
			ll mid=l+r>>1;
			if(mid*(mid+1)/2>=x) r=mid;//找最大,这个数值单独出现,不需要考虑二分最左最大还是最右最大
			else l=mid+1;
		}
		cout<<l<<'\n';
		return;
	}
	else
	{
		x=x-top;
		ll l=0,r=k-1;
		while(l<r)
		{
			ll mid=l+r>>1;
			if(low- mid*(mid+1)/2<=x) r=mid;
			else l=mid+1;
		}
		if(low-(l*(l+1))/2==x) cout<<k+(k-1)-l<<'\n';
		else cout<<k+(k-1)-(l-1)<<'\n';
	}
	
}

int main()
{
	close();
	int T; cin>>T;
	while (T--) solve();
	return 0;
}
//发 2*k-1 条讯息,每条有些表情,每行从1递增到k再递减到1,最多发送方x个表情
//求最多发送多少行
//从1到k有单调性,从k到1又有单调性